package com.his.struts.dao.hospitalInfo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.his.struts.dao.help.ConnectsImp;
import com.his.struts.form.FunctionForm;
import com.his.struts.form.HospitalInfoForm;
import com.his.struts.util.DbUtil;

/**
 * 医院信息
 * @author xiaoweiliang
 *
 */
public class HospitalInfoImp implements HospitalInfoDao{
	Logger log = Logger.getLogger(HospitalInfoImp.class);
	DbUtil db = new DbUtil();
	
	/**
	 * 更新医院信息
	 * @param info 医院信息bean
	 */
	public void updateHospitalInfo(HospitalInfoForm info){
		ArrayList list = new ArrayList();
		list.add(info.getHospitalName());
		list.add(info.getJianjie());
		list.add(info.getYejiaoxinxi());
		String sql ="update hospitalinfo set hospitalName=?, jianjie=? ,yejiaoxinxi=?";
		if(info.getHospitalLogo() != null && info.getHospitalLogo() != ""){
			sql = sql + ", hospitalLogo=?";
			list.add(info.getHospitalLogo());
		}
		if(info.getFavicon() != null && info.getFavicon() != ""){
			sql = sql + ", favicon=?";
			list.add(info.getFavicon());
		}
		db.executeUpdate(sql, list);
		db.closeAll();
		
	}
	
	/**
	 * 读取医院信息
	 * @return 医院信息
	 */
	public HospitalInfoForm getHospitalInfo(){
		String sql = "select * from hospitalinfo";
		ResultSet rs = db.executeQuery(sql, null);
		HospitalInfoForm info = new HospitalInfoForm();
		try {
			if(rs.next()){
				info.setId(rs.getInt("id"));
				info.setFavicon(rs.getString("favicon"));
				info.setHospitalLogo(rs.getString("hospitalLogo"));
				info.setHospitalName(rs.getString("hospitalName"));
				info.setJianjie(rs.getString("jianjie"));
				info.setYejiaoxinxi(rs.getString("yejiaoxinxi"));
			}
		} catch (SQLException e) {
			log.error(e.getMessage());
		}finally{
			db.closeAll();
		}
		
		return info;
	}
}
